<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Comment extends CI_Controller {
// 
//  comment.php
//  phpweb
//  
//  Created by WillLee on 2011-07-18.
//  Copyright 2011 lishuzu. All rights reserved.
// 
	function __construct()
	{
		parent::__construct();
	
		$this->load->model('common/security_model');
		if($this->security_model->isLogin() === FALSE){
			showmessage('请登录', 'login', 2);
		}
		$this->load->model('user_model');
		$this->load->model('comment_model');
		$this->user = $this->session->userdata('user') ? $this->session->userdata('user') : '';
	}
	
	public function index()
	{
		if (submitcheck('commentsbumit')) {
			$set = $this->input->post('set', true);
			foreach ($set as $key => $value) {
				if (empty($value)) {
					showmessage('您提交的数据不正确');
				}
			}
			switch ($set['idtype']) {
				case 'talkid':
					$backurl = base_url()."talk/detail/?uid=".$set['uid']."&talkid=".$set['id'];
					break;
				case 'workid':
					$backurl = base_url()."work/index/".$set['id'];
					break;
				default:
					$backurl = base_url();
					break;
			}
			$res = $this->comment_model->add_comment(intval($set['id']), $set['idtype'], $set['message']);
			if ($res) {
				redirect($this->agent->referrer());
			}else{
				showmessage('评论失败', $this->agent->referrer(), 2);
			}
		}else{
			showmessage('您还没进行提交操作');
		}
		
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */